﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Management;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace win32_deskyopdisplay
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SelectQuery Sq = new SelectQuery("Win32_DesktopMonitor");
            ManagementObjectSearcher objOSDetails = new ManagementObjectSearcher(Sq);
            ManagementObjectCollection osDetailsCollection = objOSDetails.Get();
            StringBuilder sb = new StringBuilder();
            foreach (ManagementObject mo in osDetailsCollection)
            {
                sb.AppendLine(string.Format("Name : {0}", (string)mo["Name"]));
                sb.AppendLine(string.Format("Availability: {0}", (ushort)mo["Availability"]));
                sb.AppendLine(string.Format("Caption: {0}", (string)mo["Caption"]));
                sb.AppendLine(string.Format("InstallDate: {0}", Convert.ToDateTime(mo["InstallDate"]).ToString()));
                sb.AppendLine(string.Format("ConfigManagerUserConfig: {0}", mo["ConfigManagerUserConfig"].ToString()));
                sb.AppendLine(string.Format("CreationClassName : {0}", (string)mo["CreationClassName"]));
                sb.AppendLine(string.Format("Description: {0}", (string)mo["Description"]));
                sb.AppendLine(string.Format("DeviceID : {0}", (string)mo["DeviceID"]));
                sb.AppendLine(string.Format("ErrorCleared: {0}", (string)mo["ErrorCleared"]));
                sb.AppendLine(string.Format("ErrorDescription : {0}", (string)mo["ErrorDescription"]));
                sb.AppendLine(string.Format("ConfigManagerUserConfig: {0}", mo["ConfigManagerUserConfig"].ToString()));
                sb.AppendLine(string.Format("LastErrorCode : {0}", mo["LastErrorCode"]).ToString());
                sb.AppendLine(string.Format("MonitorManufacturer : {0}", mo["MonitorManufacturer"]).ToString());
                sb.AppendLine(string.Format("PNPDeviceID: {0}", (string)mo["PNPDeviceID"]));
                sb.AppendLine(string.Format("MonitorType: {0}", (string)mo["MonitorType"]));
                sb.AppendLine(string.Format("PixelsPerXLogicalInch : {0}", mo["PixelsPerXLogicalInch"].ToString()));
                sb.AppendLine(string.Format("PixelsPerYLogicalInch: {0}", mo["PixelsPerYLogicalInch"].ToString()));
                if (mo["ScreenHeight"] != null)
                    sb.AppendLine(string.Format("ScreenHeight: {0}", mo["ScreenHeight"].ToString()));
                if (mo["ScreenWidth"] != null)
                    sb.AppendLine(string.Format("ScreenWidth : {0}", mo["ScreenWidth"]).ToString());
                sb.AppendLine(string.Format("Status : {0}", (string)mo["Status"]));
                sb.AppendLine(string.Format("SystemCreationClassName : {0}", (string)mo["SystemCreationClassName"]));
                sb.AppendLine(string.Format("SystemName: {0}", (string)mo["SystemName"]));
            }
            textBox1.Text = sb.ToString();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            List<myScreen> scrs = ScreenHelper.myGetAllScreen();
            StringBuilder sb = new StringBuilder();
            foreach (myScreen s in scrs)
            {
                sb.AppendLine(string.Format("Device Name : {0}", s.DeviceName));
                sb.AppendLine(string.Format("Device ID : {0}", s.ScreenDevice.DeviceID));
                sb.AppendLine(string.Format("Device Name : {0}", s.ScreenDevice.DeviceName));
                sb.AppendLine(string.Format("Device string : {0}", s.ScreenDevice.DeviceString));
                sb.AppendLine(string.Format("Device key : {0}", s.ScreenDevice.DeviceKey));
            }
            textBox2.Text = sb.ToString();
        }
    }
}
